﻿using Little.Soldier.SWIFT;
using Little.Soldier.SWIFT.Definition;
using System;
using System.Text;

namespace Little.Soldier.SWIFT.Messages.Category5
{
  public class Tag34B : SwiftTagWrapper
  {
    public string Value
    {
      get
      {
        return this.GetValue();
      }
      set
      {
        this.SetValue("34B", value);
      }
    }

    public string Currency
    {
      get
      {
        string str1 = (string) null;
        string str2 = this.Value;
        if (str2 != null && str2.Length > 0)
          str1 = str2.Length <= 3 ? str2.Substring(0) : str2.Substring(0, 3);
        return str1;
      }
      set
      {
        int num1 = 0;
        int num2 = 3;
        StringBuilder stringBuilder = new StringBuilder();
        string str1 = this.Value ?? string.Empty;
        str1.PadLeft(num1, ' ');
        stringBuilder.Append(str1.Substring(0, num1));
        string str2 = ((object) value).ToString();
        if (str2.Length > num2)
          str2 = str2.Substring(0, num2);
        if (str1.Length > num1 + num2)
          str2 = str2.PadLeft(num2, ' ');
        stringBuilder.Append(str2);
        if (str1.Length > num1 + num2)
          stringBuilder.Append(str1.Substring(num1 + num2));
        this.Value = ((object) stringBuilder).ToString();
      }
    }

    public Decimal Amount
    {
      get
      {
        Decimal result = new Decimal(0);
        string str = this.Value;
        if (str != null && str.Length > 3)
          Decimal.TryParse(str.Length <= 18 ? str.Substring(3) : str.Substring(3, 15), out result);
        return result;
      }
      set
      {
        int num1 = 3;
        int num2 = 15;
        StringBuilder stringBuilder = new StringBuilder();
        string str1 = this.Value ?? string.Empty;
        str1.PadLeft(num1, ' ');
        stringBuilder.Append(str1.Substring(0, num1));
        string str2 = value.ToString();
        if (str2.Length > num2)
          str2 = str2.Substring(0, num2);
        if (str1.Length > num1 + num2)
          str2 = str2.PadLeft(num2, ' ');
        stringBuilder.Append(str2);
        if (str1.Length > num1 + num2)
          stringBuilder.Append(str1.Substring(num1 + num2));
        this.Value = ((object) stringBuilder).ToString();
      }
    }

    internal Tag34B(SwiftElement parent, int index, SwiftDefinitionElement definition)
      : base(parent, index, definition)
    {
    }
  }
}
